<template>
  <el-dialog
    :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="商家" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家"></el-input>
    </el-form-item>
    <el-form-item label="操作人" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="操作人"></el-input>
    </el-form-item>
    <el-form-item label="会员" prop="memberId">
      <el-input v-model="dataForm.memberId" placeholder="会员"></el-input>
    </el-form-item>
    <el-form-item label="入住类型（0全天1时租2自用3免费）" prop="checkinType">
      <el-input v-model="dataForm.checkinType" placeholder="入住类型（0全天1时租2自用3免费）"></el-input>
    </el-form-item>
    <el-form-item label="预抵时间" prop="arrivalsTime">
      <el-input v-model="dataForm.arrivalsTime" placeholder="预抵时间"></el-input>
    </el-form-item>
    <el-form-item label="预离时间" prop="predissociationTime">
      <el-input v-model="dataForm.predissociationTime" placeholder="预离时间"></el-input>
    </el-form-item>
    <el-form-item label="天数" prop="days">
      <el-input v-model="dataForm.days" placeholder="天数"></el-input>
    </el-form-item>
    <el-form-item label="客源（0散客1会员2协议单位3中介）" prop="sourceType">
      <el-input v-model="dataForm.sourceType" placeholder="客源（0散客1会员2协议单位3中介）"></el-input>
    </el-form-item>
    <el-form-item label="客源标记" prop="sourceName">
      <el-input v-model="dataForm.sourceName" placeholder="客源标记"></el-input>
    </el-form-item>
    <el-form-item label="市场活动" prop="activityId">
      <el-input v-model="dataForm.activityId" placeholder="市场活动"></el-input>
    </el-form-item>
    <el-form-item label="担保方式（0无担保1担保2OTA担保）" prop="guaranteeType">
      <el-input v-model="dataForm.guaranteeType" placeholder="担保方式（0无担保1担保2OTA担保）"></el-input>
    </el-form-item>
    <el-form-item label="销售" prop="saleId">
      <el-input v-model="dataForm.saleId" placeholder="销售"></el-input>
    </el-form-item>
    <el-form-item label="外部单号" prop="externalNo">
      <el-input v-model="dataForm.externalNo" placeholder="外部单号"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="房间数" prop="roomsNum">
      <el-input v-model="dataForm.roomsNum" placeholder="房间数"></el-input>
    </el-form-item>
    <el-form-item label="占房天数" prop="roomsDays">
      <el-input v-model="dataForm.roomsDays" placeholder="占房天数"></el-input>
    </el-form-item>
    <el-form-item label="总价" prop="totalPrice">
      <el-input v-model="dataForm.totalPrice" placeholder="总价"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="creatTime">
      <el-input v-model="dataForm.creatTime" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          userId: '',
          memberId: '',
          checkinType: '',
          arrivalsTime: '',
          predissociationTime: '',
          days: '',
          sourceType: '',
          sourceName: '',
          activityId: '',
          guaranteeType: '',
          saleId: '',
          externalNo: '',
          remarks: '',
          roomsNum: '',
          roomsDays: '',
          totalPrice: '',
          creatTime: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '操作人不能为空', trigger: 'blur' }
          ],
          memberId: [
            { required: true, message: '会员不能为空', trigger: 'blur' }
          ],
          checkinType: [
            { required: true, message: '入住类型（0全天1时租2自用3免费）不能为空', trigger: 'blur' }
          ],
          arrivalsTime: [
            { required: true, message: '预抵时间不能为空', trigger: 'blur' }
          ],
          predissociationTime: [
            { required: true, message: '预离时间不能为空', trigger: 'blur' }
          ],
          days: [
            { required: true, message: '天数不能为空', trigger: 'blur' }
          ],
          sourceType: [
            { required: true, message: '客源（0散客1会员2协议单位3中介）不能为空', trigger: 'blur' }
          ],
          sourceName: [
            { required: true, message: '客源标记不能为空', trigger: 'blur' }
          ],
          activityId: [
            { required: true, message: '市场活动不能为空', trigger: 'blur' }
          ],
          guaranteeType: [
            { required: true, message: '担保方式（0无担保1担保2OTA担保）不能为空', trigger: 'blur' }
          ],
          saleId: [
            { required: true, message: '销售不能为空', trigger: 'blur' }
          ],
          externalNo: [
            { required: true, message: '外部单号不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          roomsNum: [
            { required: true, message: '房间数不能为空', trigger: 'blur' }
          ],
          roomsDays: [
            { required: true, message: '占房天数不能为空', trigger: 'blur' }
          ],
          totalPrice: [
            { required: true, message: '总价不能为空', trigger: 'blur' }
          ],
          creatTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tHotelFloorRoomCheckinSingle.sellerId
                this.dataForm.userId = data.tHotelFloorRoomCheckinSingle.userId
                this.dataForm.memberId = data.tHotelFloorRoomCheckinSingle.memberId
                this.dataForm.checkinType = data.tHotelFloorRoomCheckinSingle.checkinType
                this.dataForm.arrivalsTime = data.tHotelFloorRoomCheckinSingle.arrivalsTime
                this.dataForm.predissociationTime = data.tHotelFloorRoomCheckinSingle.predissociationTime
                this.dataForm.days = data.tHotelFloorRoomCheckinSingle.days
                this.dataForm.sourceType = data.tHotelFloorRoomCheckinSingle.sourceType
                this.dataForm.sourceName = data.tHotelFloorRoomCheckinSingle.sourceName
                this.dataForm.activityId = data.tHotelFloorRoomCheckinSingle.activityId
                this.dataForm.guaranteeType = data.tHotelFloorRoomCheckinSingle.guaranteeType
                this.dataForm.saleId = data.tHotelFloorRoomCheckinSingle.saleId
                this.dataForm.externalNo = data.tHotelFloorRoomCheckinSingle.externalNo
                this.dataForm.remarks = data.tHotelFloorRoomCheckinSingle.remarks
                this.dataForm.roomsNum = data.tHotelFloorRoomCheckinSingle.roomsNum
                this.dataForm.roomsDays = data.tHotelFloorRoomCheckinSingle.roomsDays
                this.dataForm.totalPrice = data.tHotelFloorRoomCheckinSingle.totalPrice
                this.dataForm.creatTime = data.tHotelFloorRoomCheckinSingle.creatTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'userId': this.dataForm.userId,
                'memberId': this.dataForm.memberId,
                'checkinType': this.dataForm.checkinType,
                'arrivalsTime': this.dataForm.arrivalsTime,
                'predissociationTime': this.dataForm.predissociationTime,
                'days': this.dataForm.days,
                'sourceType': this.dataForm.sourceType,
                'sourceName': this.dataForm.sourceName,
                'activityId': this.dataForm.activityId,
                'guaranteeType': this.dataForm.guaranteeType,
                'saleId': this.dataForm.saleId,
                'externalNo': this.dataForm.externalNo,
                'remarks': this.dataForm.remarks,
                'roomsNum': this.dataForm.roomsNum,
                'roomsDays': this.dataForm.roomsDays,
                'totalPrice': this.dataForm.totalPrice,
                'creatTime': this.dataForm.creatTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
